#ifndef DLGATTRIBUTI_H
#define DLGATTRIBUTI_H



#include "config.h"
#include "DB_Manager.h"

#include "tabellaicone.h"
#include "strutturaicone.h"

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QListWidget>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout>


class IconScroller : public QListWidget
{
     Q_OBJECT
//
public:
IconScroller( bool enable = false , QWidget* parent = 0 )
	: QListWidget( parent )
{
     enableout = enable;
     setSelectionMode ( QAbstractItemView::ExtendedSelection ); 
     setAcceptDrops(true);
     setDropIndicatorShown(false); 
     if (enable) {
       setDragEnabled(true); 
     }
     ///////setIconSize ( QSize(80,80));
}

void mousePressEvent(QMouseEvent *event)
{
   if (enableout) {
     QListWidgetItem *child = itemAt(event->pos());
     if (!child) {
     return;  
     }
     /* IcoLine = hotel attribut icon mit beschreibung in 6 sprachen und
     int kategorie int id  + pixmap 30x30 */
     IcoLine Io = child->data(Qt::UserRole).value<IcoLine>();
     
     QPixmap dragicon = Io.pix().scaledToWidth(Io.pix().width() * 3); /* zoom it */
     /* TabIcone liste von IcoLine */
     TabIcone dd;
     dd.all_lines.append(Io);
     
     QList<QListWidgetItem *> tutti = selectedItems();
     
     for (int i=0; i<tutti.size(); i++) {
        QListWidgetItem *pane = tutti[i];
        IcoLine Iter = pane->data(Qt::UserRole).value<IcoLine>();
        dd.all_lines.append(Iter);
     }
     
     QString stream = SaveTabelicon(dd); /* QDataStream zu toBase64 fuer sql*/
     QMimeData *mimeData = new QMimeData;
     mimeData->setData("application/x-atticonhotel",stream.toUtf8());
     
     QDrag *drag = new QDrag(this);
     drag->setMimeData(mimeData);
     drag->setPixmap(dragicon);
     ///////drag->setHotSpot(event->pos() - ????? ); //////  
     
     if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
          qDebug() << "### drag move it " << Io.id();
     }
     
     }
     
   QListWidget::mousePressEvent(event);
}
void dropEvent(QDropEvent *event)
{
     ///////qDebug() << "### dropEvent";
    if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
        QByteArray itemData = event->mimeData()->data("application/x-atticonhotel");
         //////////qDebug() << "### dropEvent  entra siiiiiiiiiiii ";
         QString daten = QString::fromUtf8(itemData.data());
         TabIcone liste = OpenTabelicon(daten);
         emit AppendList(liste);
         event->accept();
         
    } else {
        event->ignore();
    }
}



void dragEnterEvent(QDragEnterEvent *event)
{
     qDebug() << "### dragEnterEvent ";
     
    if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
          qDebug() << "### dragEnterEvent si ";
        event->acceptProposedAction();
    } else {
        event->ignore();
    }
}

void dragMoveEvent(QDragMoveEvent *event)
{
     qDebug() << "### dragMoveEvent ";
     
    if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
         qDebug() << "### dragMoveEvent si ";
        event->acceptProposedAction();
    } else {
        event->ignore();
    }
}
bool enableout;
signals:
   void AppendList(TabIcone);
public slots:
     
};






class DLGAttributi : public QDialog
{
     Q_OBJECT
//
public:
DLGAttributi( DB_Manager * dbin , int catessss , QString Exists_Atts = QString() );
QStringList Lists();
QGridLayout *gridLayout;
QGroupBox *groupBox;
QGridLayout *gridLayout1;
QHBoxLayout *hboxLayout;
IconScroller *master;
QVBoxLayout *vboxLayout;
QToolButton *xdelete;
QToolButton *xappend;
QSpacerItem *spacerItem;
IconScroller *slave;
QHBoxLayout *hboxLayout1;
QSpacerItem *spacerItem1;
QPushButton *accetta;
QPushButton *Rigetta;
QModelIndex Master_index;
QModelIndex Slave_index;
QString title;
QList<IcoLine> li;
protected:
     int CountCates( const int cate );
     void fillUserSetting( QStringList list = QStringList() );
     bool HavingItem( const int chars );
     void LoadConfig( const int kategoria );
private:
signals:
public slots:
     void MActivate( const QModelIndex &index );
     void SActivate( const QModelIndex &index );
     void on_xappend_triggered();
     void on_xdelete_triggered();
     void InsertList( TabIcone e );
};



//
#endif // DLGATTRIBUTI_H

